#include <iostream>
#include "simplemedia/simplemedia.h"

#define RTSP_URL "rtsp://192.168.1.10:554/user=admin&password=&channel=1&stream=0.sdp?"

int main(int argc, char const *argv[])
{
    simplemedia::RTSPMediaClient rtspstream;

    rtspstream.DataReceiveRegister([](int nread, uint8_t *data, bool iskey){
        fprintf(stderr, "Frame size: %d, is key frame: %s\n", nread, (iskey? "yes" : "no"));
    });

    rtspstream.StatusUpdateHandleRegister([](
        bool connect, const simplemedia::RTSPMediaClientResolution_t &resolution)
    {
        fprintf(stderr, "connect status : %d\n", connect);
        fprintf(stderr, "\t horizontal      : %d\n", resolution.horizontal);
        fprintf(stderr, "\t vertical        : %d\n", resolution.vertical);
        fprintf(stderr, "\t numerator       : %d\n", resolution.numerator);
        fprintf(stderr, "\t denominator     : %d\n", resolution.denominator);
    });

    rtspstream.Start(RTSP_URL);

    // Just block till user tells us to quit.
    std::cout << "please enter the charater 'q' to exit." << std::endl;
    while (std::tolower(std::cin.get()) != 'q')
        ;

    rtspstream.Stop();

    return 0;
}
